<html>
<head>
<title>ListaZakupowDao.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
.ln { color: rgb(0,0,0); font-weight: normal; font-style: normal; }
.s0 { color: rgb(0,0,128); font-weight: bold; }
.s1 { }
.s2 { color: rgb(0,128,0); font-weight: bold; }
.s3 { color: rgb(0,0,255); }
</style>
</head>
<BODY BGCOLOR="#ffffff">
<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH="100%" BGCOLOR="#C0C0C0" >
<TR><TD><CENTER>
<FONT FACE="Arial, Helvetica" COLOR="#000000">
ListaZakupowDao.java</FONT>
</center></TD></TR></TABLE>
<pre>

<span class="s0">package </span><span class="s1">com.example.lista_zakupow.database.dao; 
 
</span><span class="s0">import </span><span class="s1">android.content.ContentValues; 
</span><span class="s0">import </span><span class="s1">android.content.Context; 
</span><span class="s0">import </span><span class="s1">android.database.Cursor; 
</span><span class="s0">import </span><span class="s1">android.database.sqlite.SQLiteDatabase; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.DBHelper; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.adapters.DatabaseAdapter; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.exceptions.OperationFailedException; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.exceptions.RecordNotFoundException; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.utils.ListContentValuesBuilder; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.utils.ListUtilities; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.database.utils.tables_headers.ListaZakupowTableHeaders; 
</span><span class="s0">import </span><span class="s1">com.example.lista_zakupow.zakupy.ListaZakupow; 
 
</span><span class="s0">import </span><span class="s1">java.util.List; 
 
</span><span class="s0">public class </span><span class="s1">ListaZakupowDao { 
 
    </span><span class="s0">private final </span><span class="s1">String tableName = ListaZakupowTableHeaders.TABLE_NAME; 
 
    </span><span class="s0">private </span><span class="s1">DatabaseAdapter databaseAdapter; 
 
    </span><span class="s0">private </span><span class="s1">SQLiteDatabase database; 
 
 
    </span><span class="s0">public </span><span class="s1">ListaZakupowDao(Context context) { 
        databaseAdapter = DatabaseAdapter.getInstance(); 
        database = databaseAdapter.open(context); 
    } 
 
    </span><span class="s0">public </span><span class="s1">ListaZakupowDao(DBHelper dbHelper) { 
        databaseAdapter = DatabaseAdapter.getInstance(); 
        database = databaseAdapter.open(dbHelper); 
    } 
 
    </span><span class="s0">public </span><span class="s1">List&lt;ListaZakupow&gt; getAllListaZakupow() { 
        Cursor cursor = database.query(tableName, </span><span class="s0">null</span><span class="s1">, </span><span class="s0">null</span><span class="s1">, </span><span class="s0">null</span><span class="s1">, </span><span class="s0">null</span><span class="s1">, </span><span class="s0">null</span><span class="s1">, </span><span class="s0">null</span><span class="s1">); 
        List&lt;ListaZakupow&gt; listaZakupow = ListUtilities.getAllListaZakupowFromCursorObiect(cursor); 
        cursor.close(); 
        </span><span class="s0">return </span><span class="s1">listaZakupow; 
    } 
 
    </span><span class="s0">public </span><span class="s1">ListaZakupow save(ListaZakupow listaZakupow) { 
        ContentValues newTaskValues = ListContentValuesBuilder.createContentValuesByList(listaZakupow); 
        </span><span class="s0">long </span><span class="s1">res = database.insert(tableName, </span><span class="s0">null</span><span class="s1">, newTaskValues); 
        validDBOperation(res); 
        listaZakupow.setId(res); 
        </span><span class="s0">return </span><span class="s1">listaZakupow; 
    } 
 
    </span><span class="s0">public </span><span class="s1">ListaZakupow update(ListaZakupow listaZakupow) { 
        String where = ListaZakupowTableHeaders.LIST_ID + </span><span class="s2">&quot;=&quot; </span><span class="s1">+ listaZakupow.getId(); 
        ContentValues updateTaskValues = ListContentValuesBuilder.createContentValuesByList(listaZakupow); 
        </span><span class="s0">long </span><span class="s1">res = database.update(tableName, updateTaskValues, where, </span><span class="s0">null</span><span class="s1">); 
        validDBOperation(res); 
        </span><span class="s0">return </span><span class="s1">listaZakupow; 
    } 
 
 
    </span><span class="s0">public int </span><span class="s1">delete(ListaZakupow listaZakupow) { 
        String where = ListaZakupowTableHeaders.LIST_ID + </span><span class="s2">&quot;=&quot; </span><span class="s1">+ listaZakupow.getId(); 
        </span><span class="s0">int </span><span class="s1">res = database.delete(tableName, where, </span><span class="s0">null</span><span class="s1">); 
        validDBOperation(res); 
        </span><span class="s0">return </span><span class="s1">res; 
    } 
 
    </span><span class="s0">private void </span><span class="s1">validDBOperation(</span><span class="s0">long </span><span class="s1">res) { 
        </span><span class="s0">if </span><span class="s1">(res == -</span><span class="s3">1</span><span class="s1">) { 
            </span><span class="s0">throw new </span><span class="s1">OperationFailedException(); 
        } 
        </span><span class="s0">if </span><span class="s1">(res == </span><span class="s3">0</span><span class="s1">) { 
            </span><span class="s0">throw new </span><span class="s1">RecordNotFoundException(); 
        } 
    } 
} 
</span></pre>
</body>
</html>